<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
</head>

<body>

    <p>替换 "microsoft" 为 "Runoob" :</p>
    <button onclick="myFunction()">点我</button>
    <button onclick="myFunction2()">点我2</button>
    <p id="demo">Visit Microsoft!</p>
    <p id="demo2">Visit Microsoft!</p>
    <script>
        function myFunction() {
            var str = document.getElementById("demo").innerHTML;
            var txt = str.replace(/microsoft/i, "Runoob");
            document.getElementById("demo").innerHTML = txt;
        }

        function myFunction2() {
            var str = document.getElementById("demo2").innerHTML; 
            var txt = str.replace("Microsoft","Runoob");
            document.getElementById("demo2").innerHTML = txt;
        }
// JS 判断输入是否为数字、字母、下划线组成
        function isValid(str) { return /^\w+$/.test(str); }
            str = "1234abd__"
            document.write(isValid(str));
            document.write("<br>");

            str2 = "$32343#"
            document.write(isValid(str2));
            document.write("<br>");
// JS 判断字符串是否全部为字母
            val = "123456"
            var isletter = /^[a-zA-Z]+$/.test(val);
            document.write(isletter);
            document.write("<br>");

            val2 = "asaaa"
            var isletter2 = /^[a-zA-Z]+$/.test(val2);
            document.write(isletter2);
// JS 判断字符串是否全部为数字
            val = "123456"
            var isnum = /^\d+$/.test(val);
            document.write(isnum);
            document.write("<br>");

            val2 = "as123"
            var isnum2 = /^\d+$/.test(val2);
            document.write(isnum2);
    </script>

</body>

</html>